package ims.db.update.prodType;

import ims.beans.ProductType;
import ims.db.AbstractDAO;
import ims.db.AbstractDbRequest;
import ims.db.AbstractDbResponse;

import java.sql.SQLException;
import java.sql.Statement;

public class UpdateProdTypeDAO extends AbstractDAO {

	public UpdateProdTypeDAO() throws ClassNotFoundException, SQLException {
		super();
	}

	@Override
	public AbstractDbResponse execute(AbstractDbRequest dbRequest) 
	{
		UpdateProdTypeDbResponse response = new UpdateProdTypeDbResponse();
		UpdateProdTypeDbRequest request = (UpdateProdTypeDbRequest)dbRequest;
        try 
        {
        	Statement stmt = conn.createStatement();
        	ProductType prodType = request.getProdType();
        	StringBuffer sql = new StringBuffer();
        	sql.append("update ProductType set productType ='").append(prodType.getProdType()).append("' where prodTypeId ='").append(prodType.getProdTypeId()).append("'");
        		
        	
    		int retCd = stmt.executeUpdate(sql.toString());
    		if (retCd == 1)
    			response.setMsg("Product type: "+ prodType.getProdType()+" updated successfully");
    		else
    			response.setMsg("Unable update product type: "+ prodType.getProdType());
            stmt.close();
            conn.close();
        } 
        catch (SQLException sqlEx)
        {
        	sqlEx.printStackTrace();
        }
        return response;
	}
}
